<%--
  Created by IntelliJ IDEA.
  User: 12515
  Date: 2019/10/8
  Time: 11:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <base href="${pageContext.request.contextPath}/">
    <link rel="stylesheet" href="bootstrap-3.3.7/css/bootstrap.min.css" />
    <script type="text/javascript" src="bootstrap-3.3.7/js/jquery-3.4.1.min.js" ></script>
    <script type="text/javascript" src="bootstrap-3.3.7/js/bootstrap.min.js" ></script>
    <script type="text/javascript">
        function test(id) {
            console.log("---");
            console.log(id);
            var v = $("#input_"+id);
            var s = $("#span_"+id);
            var i = v.val();
            var num = s.text();
            console.log(i);
            if (i=='false'){
                v.val("true");
                s.attr("class","glyphicon glyphicon-heart")
                s.text(parseInt(num)+1);
                $.post("zan/add.do",{itemId:id,type:i},function (data){
                    var num = eval(data);
                    s.text = num;
                },"json");
            } else {
                v.val("false");
                s.attr("class","glyphicon glyphicon-heart-empty");
                s.text(parseInt(num)-1);
                $.post("zan/add.do",{itemId:id,type:i},function (data){
                    var num = eval(data);
                    s.text = num;
                },"json");
            }
        }
    </script>

</head>
<body>

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">
                <span class="glyphicon glyphicon-star" aria-hidden="true"></span>
            </a>
        </div>
        <p class="navbar-text"><shiro:principal property="userName"/>,欢迎您！</p>
        [用户角色:<shiro:hasRole name="manager">manager</shiro:hasRole>
        <shiro:hasRole name="user">user</shiro:hasRole>
        <shiro:hasRole name="cmanager">cmanager</shiro:hasRole>
        <shiro:hasRole name="mmanager">mmanager</shiro:hasRole>
        <shiro:hasRole name="xmanager">xmanager</shiro:hasRole>]
    </div>
</nav>

C模块
<ul>
    <shiro:hasPermission name="sys:c:save"><li>添加C</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:c:delete"><li>删除C</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:c:update"><li>修改C</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:c:find"><li>查询C</li></shiro:hasPermission>
</ul>

X模块
<ul>
    <shiro:hasPermission name="sys:x:save"><li>添加X</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:x:delete"><li>删除X</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:x:update"><li>修改X</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:x:find"><li>查询X</li></shiro:hasPermission>
</ul>
M模块
<ul>
    <shiro:hasPermission name="sys:m:save"><li>添加M</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:m:delete"><li>删除M</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:m:update"><li>修改M</li></shiro:hasPermission>
    <shiro:hasPermission name="sys:m:find"><li>查询M</li></shiro:hasPermission>
</ul>

<div class="container">
    <table class="table">
        <caption>商品列表</caption>
        <thead>
        <tr>
            <th>商品标号</th>
            <th>商品名称</th>
            <th>操作</th>
        </tr>
        </thead>
        <c:forEach items="${items}" var="item">
            <tr>
                <td>${item.item.itemId}</td>
                <td>${item.item.itemName}</td>
                <td><input type="hidden" id="input_${item.item.itemId}" value="${item.zanState}"></td>
                <c:if test="${item.zanState==false}">
                    <td><span id="span_${item.item.itemId}" class="glyphicon glyphicon-heart-empty" aria-hidden="true" onclick="test('${item.item.itemId}')">${item.zanCount}</span></td>
                </c:if>
                <c:if test="${item.zanState==true}">
                    <td><span id="span_${item.item.itemId}" class="glyphicon glyphicon-heart" aria-hidden="true" onclick="test('${item.item.itemId}')">${item.zanCount}</span></td>
                </c:if>

            </tr>
        </c:forEach>
    </table>
</div>
</body>
</html>
